﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.IO {

	/// <summary>
	/// Contains useful methods for processing pathes in Vortex2D engine
	/// </summary>
	public static class PathUtils {

		/// <summary>
		/// Determines whether path is context absolute (contains single forward '\' or '/')
		/// </summary>
		/// <param name="path">The path to checks.</param>
		/// <returns>
		/// 	<c>true</c> if path is context absolute; otherwise, <c>false</c>.
		/// </returns>
		public static bool IsPathContextRooted(string path) {
			if (null == path) throw new ArgumentNullException("path");

			if (path.Length > 0 && (path[0] == '\\' || path[0] == '/' )) {
				if (path.Length == 1 || path[1] != '\\' && path[1] != '/') {
					return true;
				}
			}
			return false;
		}

		/// <summary>
		/// Escapes the context rooted path.
		/// </summary>
		/// <param name="path">The path to escape.</param>
		/// <returns>Application relative path</returns>
		public static string EscapeContextRootedPath(string path) {
			if (path == null) throw new ArgumentNullException("path");
			if (path.Length > 0) {
				return path.Substring(1);
			} else {
				return path;
			}
		}

		/// <summary>
		/// Determines whether is path rooted or not.
		/// </summary>
		/// <param name="path">The path.</param>
		/// <returns>
		/// 	<c>true</c> if path is rooted; otherwise, <c>false</c>.
		/// </returns>
		public static bool IsPathRooted(string path) {
			if (null == path) throw new ArgumentNullException("path");

			return System.IO.Path.IsPathRooted(path);
		}
	}
}
